package com.lemon.controller;
import com.lemon.domain.PageResult;
import com.lemon.domain.Result;
import com.lemon.domain.StocktakingTask;
import com.lemon.service.StocktakingTaskService;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

/**
* 定时盘点任务表(stocktaking_task)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/stocktaking_task")
public class StocktakingTaskController {

    @Autowired
    private StocktakingTaskService stocktakingTaskService;

    /**
     * 手动执行一次定时任务
     */
    @PostMapping("/execute/{taskId}")
    public Result executeTaskOnce(@PathVariable Long taskId) {
        stocktakingTaskService.executeTaskOnce(taskId);
        return Result.success();
    }

    @GetMapping
    public Result getPage(Integer page, Integer pageSize, String taskName, Integer category, Integer isEnable) {
        PageResult list =  stocktakingTaskService.getPage(page, pageSize, taskName, category, isEnable);
        return Result.success(list);
    }

    /**
     * 添加定时盘点任务
     */
    @PostMapping
    public Result addStocktakingTask(@RequestBody StocktakingTask task) {
        // 添加任务
        stocktakingTaskService.addStocktakingTask(task);
        return Result.success();
    }

    /**
     * 更新定时盘点任务
     */
    @PutMapping
    public Result updateStocktakingTask(@RequestBody StocktakingTask task) {
        // 更新任务
        stocktakingTaskService.updateStocktakingTask(task);
        return Result.success();
    }

    /**
     * 删除定时盘点任务
     */
    @DeleteMapping("/{taskId}")
    public Result deleteStocktakingTask(@PathVariable Long taskId) {
        stocktakingTaskService.deleteStocktakingTask(taskId);
        return Result.success();
    }
}
